#-*- coding:UTF-8-*-

__author__='zhaoxp'

'''
threading usage:
python中的threading包中的Thread类，跟Java中的Thread非常相似的。

Thread类的方法：
start()
run()
join(timeout=None)
getName()
setName(threadName)
isAlive()
isDaemon()
setDaemon(daemonic)


'''

import threading
import time

loops=[4,2,3]

class MyThread(threading.Thread):
	def __init__(self,nsec):
		self.nsec=nsec
		threading.Thread.__init__(self)
	def run(self):
		print("MyThread"+str(self.nsec)+" run at : "+str(time.ctime()))
		time.sleep(self.nsec)
		print("MyThread"+str(self.nsec)+" end at : "+str(time.ctime()))
		
def main():
	print('-'*30)
	threads=[]
	for i in range(len(loops)):
		threads.append(MyThread(loops[i]))
		
	for i in range(len(threads)):
		threads[i].start()
		
	for i in range(len(threads)):
		threads[i].join()
		
	print("all done at : "+str(time.ctime()))

if __name__=='__main__':
	main()